package conput;

import java.util.ArrayList;

public class RWLALServer extends Server {

    private final ArrayList<String> posts = new ArrayList<String>();
    private final ReadWriteLock lock = new ReadWriteLock();

    public void write(String s) throws InterruptedException {
        lock.writeLock();
        try {
            posts.add(s);
        } finally {
            lock.unlockWrite();
        }
        size.getAndIncrement();
    }

    public String read(int i) throws InterruptedException {
        lock.readLock();
        try {
            return posts.get(i);
        } finally {
            lock.unlockRead();
        }
    }
}
